栈
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#define TYPE int 

typedef struct Stack
{
	TYPE* arr;	//内存首地址
	int  len;	//栈的容量
	int top; 	//栈的下标
}Stack;

//判断是否为出栈序列
bool is_pop(int* in,int* out,size_t len);
//创建
Stack* creat_stack(size_t cal);
//销毁
void destory_stack(Stack* stack);
//入栈
bool push_stack(Stack* stack,TYPE data);
//出栈
bool pop_stack(Stack* stack);
//判断栈空
bool empty_stack(Stack* stack);
//栈满
bool full_stack(Stack* stack);
//查看栈顶
TYPE* top_stack(Stack* stack);

int main()
{
	Stack* stack = creat_stack(15);
/*	printf("开始入栈：\n");
	for(int i=0 ;i<15;i++)
	{
		printf("入栈%s ",push_stack(stack,i)?"成功":"失败");
		printf("栈顶:%d\n",*top_stack(stack));
	}

	printf("----------------\n开始出栈：\n");
	for(int i=0;i<15;i++)
	{
		printf("栈顶：%d ,",*top_stack(stack));
		printf("出栈：%s\n",pop_stack(stack)?"成功":"失败");
		
	}
*/		
	int arr1[7]={1,2,3,4,5,6,7},arr2[7]={5,4,6,3,2,1,7};
	if(is_pop(arr1,arr2,7))
		printf("true");
	else
		printf("wrong");
	

}



//创建
Stack* creat_stack(size_t cal)
{
	Stack* stack= malloc(sizeof(Stack));
	stack->arr = malloc(sizeof(TYPE)*cal);
	stack->len = cal;
	stack->top = -1;
	return stack;
}
//销毁
void destory_stack(Stack* stack)
{
	free(stack->arr);
	free(stack);
}
//入栈
bool push_stack(Stack* stack,TYPE data)
{
	if(full_stack(stack)) 
	return false;	
	stack->arr[++stack->top]=data;
	return true;
}

//出栈
bool pop_stack(Stack* stack)
{
	if(empty_stack(stack))
		return false;
	stack->top--;
	return true;
}
//判断栈空
bool empty_stack(Stack* stack)
{
	return -1 == stack->top;	
}

//栈满
bool full_stack(Stack* stack)
{
	return stack->top+1>=stack->len;
}

//查看栈顶
TYPE* top_stack(Stack* stack)
{
	if(empty_stack(stack))return NULL;
	return stack->arr + stack->top;
}

//判断是否为出栈序列
bool is_pop(int* in,int* out,size_t len)
{
	int flag = 0,index=0;
	for(int n = 0;n<len;n++)
	{
		for(int i=0;i<len;i++)
		{
			if(out[index] == in[i])
			{
				flag=i;
				break;
			}
		}
		for(int i=flag;i<len-1;i++)
		{
			int temp = in[i];
			in[i] =in[i+1];
			in[i+1]=temp;
		}
	index++;
	if(flag >=2)
	{
		for(int i=0;i<flag-1;i++)
		{
		if(out[index] == in[i])
			return false;
		}
	}
	}
	return true;
}



